﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Physis.Data {

    public class SortDescriptor {

        #region Private Properties

        private String fieldName = String.Empty;

        private Data.Enumerations.DataSortDirection sortDirection = Enumerations.DataSortDirection.Ascending;

        #endregion


        #region Public Properties

        public String FieldName { get { return fieldName; } set { fieldName = Functions.SetValueMaxLength (value, 60); } }

        public Data.Enumerations.DataSortDirection SortDirection { get { return sortDirection; } set { sortDirection = value; } }


        public String SqlSortList {

            get {

                String sortItem = String.Empty;


                if (FieldName.Contains (".")) { sortItem = FieldName + " "; }

                else { sortItem = "" + FieldName + " "; } // REMOVED [] FOR ORACLE SUPPORT


                switch (SortDirection) {

                    case Enumerations.DataSortDirection.Ascending: sortItem = sortItem + "ASC"; break;

                    case Enumerations.DataSortDirection.Descending: sortItem = sortItem + "DESC"; break;

                }

                return sortItem;

            }

        }

        #endregion


        #region Constructors

        public SortDescriptor () { /* DO NOTHING */ }

        public SortDescriptor (String forFieldName, Data.Enumerations.DataSortDirection forSortDirection) {

            FieldName = forFieldName;

            SortDirection = forSortDirection;

            return;

        }

        #endregion

    }

}
